import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextArea;
import javax.swing.border.LineBorder;
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JScrollPane;

public class playerStats extends JPanel {
	public playerStats(player play, List<String> commonWords) {
		setBorder(new LineBorder(new Color(192, 192, 192), 1, true));
		setLayout(null);

		//Player Label
		JLabel playerLabel = new JLabel("Player: ");
		playerLabel.setBounds(10, 11, 360, 20);
		playerLabel.setFont(new Font("Tahoma", Font.BOLD, 16));
		add(playerLabel);
		playerLabel.setText(play.getName());

		//Score
		{
			//Label
			JLabel lblScore = new JLabel("Score:");
			lblScore.setFont(new Font("Tahoma", Font.BOLD, 11));
			lblScore.setBounds(10, 31, 360, 14);
			add(lblScore);

			//Score Area
			JTextArea scoreArea = new JTextArea();
			scoreArea.setFont(new Font("Monospaced", Font.BOLD, 13));
			scoreArea.setEditable(false);
			scoreArea.setBounds(10, 52, 360, 170);
			add(scoreArea);
			
			//Get Score
			StringBuilder score = new StringBuilder();
			int[][] stats =  play.getStats();
			score.append(String.format("3-4 Letter Words: %d x 1pt = %d\n", stats[0][0], stats[1][0]));
			score.append(String.format("5 Letter Words: %d x 2pts = %d\n", stats[0][1], stats[1][1]));
			score.append(String.format("6 Letter Words: %d x 3pts = %d\n", stats[0][2], stats[1][2]));
			score.append(String.format("7 Letter Words: %d x 5pts = %d\n", stats[0][3], stats[1][3]));
			score.append(String.format("8 Letter Words: %d x 11pts = %d\n", stats[0][4], stats[1][4]));
			score.append(String.format("9 Letter Words: %d (2pts/letter) = %d\n", stats[0][5], stats[1][5]));
			score.append("\n");
			score.append("Total Accepted Words: " + stats[0][6] + "\n");
			score.append("Total Score: " + stats[1][6]);
			scoreArea.setText(score.toString());
		}

		//Accepted Words
		{
			//Label
			JLabel lblAcceptedwords = new JLabel("Accepted Words:");
			lblAcceptedwords.setFont(new Font("Tahoma", Font.BOLD, 11));
			lblAcceptedwords.setBounds(10, 233, 180, 14);
			add(lblAcceptedwords);
			
			//Scroll Bar
			JScrollPane acceptedScroll = new JScrollPane();
			acceptedScroll.setBounds(10, 258, 170, 131);
			add(acceptedScroll);
			
			//Text Area
			JTextArea acceptedArea = new JTextArea();
			acceptedArea.setEditable(false);
			acceptedArea.setFont(new Font("Monospaced", Font.BOLD, 13));
			acceptedScroll.setViewportView(acceptedArea);
			
			//Get Accepted Words
			StringBuilder acceptedWordsBuilder = new StringBuilder();
			for(String word : play.getAcceptedWords()){
				acceptedWordsBuilder.append(word + "\n");
			}
			acceptedArea.setText(acceptedWordsBuilder.toString());
		}

		//Unaccepted Words
		{
			//Label
			JLabel lblUnacceptedWords = new JLabel("Unaccepted Words:");
			lblUnacceptedWords.setFont(new Font("Tahoma", Font.BOLD, 11));
			lblUnacceptedWords.setBounds(200, 233, 170, 14);
			add(lblUnacceptedWords);
			
			//Scroll Bar
			JScrollPane unacceptedWordsScroll = new JScrollPane();
			unacceptedWordsScroll.setBounds(200, 258, 170, 131);
			add(unacceptedWordsScroll);
			
			//Text Area
			JTextArea unacceptedArea = new JTextArea();
			unacceptedArea.setEditable(false);
			unacceptedArea.setFont(new Font("Monospaced", Font.BOLD, 13));
			unacceptedWordsScroll.setViewportView(unacceptedArea);
			
			//Get Unaccepted Words
			List<String> unacceptedWords = new ArrayList<String>();
			unacceptedWords.addAll(play.getGuessedWords());
			unacceptedWords.removeAll(play.getAcceptedWords());
			unacceptedWords.removeAll(commonWords);
			StringBuilder unacceptedWordsBuilder = new StringBuilder();
			for(String word : unacceptedWords){
				unacceptedWordsBuilder.append(word + "\n");
			}
			unacceptedArea.setText(unacceptedWordsBuilder.toString());
		}
	}
}
